﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;

public partial class cjPage : System.Web.UI.Page
{
    private static landInfo landInfo = new landInfo();

    protected void Page_Load(object sender, EventArgs e)
    {
        //获取用户登陆信息
        if (Session["landInfo"] != null)
        {
            landInfo = (landInfo)Session["landInfo"];
        }
        if (!IsPostBack)
        {
            //获取班级信息
            BindBJ();
        }
    }

    #region 脚本
    /// <summary>
    /// 如果GridView中没有数据则显示提示信息
    /// </summary>
    protected void viewIsNoData()
    {
        if (gvCJ.Rows.Count == 0)
        {
            RegisterStartupScript("prompt", "<script type='text/javascript'>document.getElementById('divBrowse').innerHTML='(尚未找到相关数据)'</script>");
        }
    }
    /// <summary>
    /// 显示报消息窗口
    /// </summary>
    /// <param name="Msg"></param>
    private void MsgBoxShow(string Msg)
    {
        RegisterStartupScript("Msg", "<script type='text/javascript' language='javascript'>alert('" + Msg + "')</script>");
    }
    #endregion

    //获取班级信息
    private void BindBJ()
    {
        dropBJ.DataSource = bj_BLL.GetBJSource(landInfo.UserId);
        dropBJ.DataTextField = "bjName";
        dropBJ.DataValueField = "bjNum";
        dropBJ.DataBind();
        dropBJ.Items.Add(new ListItem("（查询所有）", "All"));
    }

    //当选择班级更改时根据所选班级查找该班学生
    protected void dropBJ_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (dropBJ.SelectedValue != "All")
        {
            gvCJ.DataSource = cj_BLL.GetCJInfo(decimal.Parse(dropBJ.SelectedValue));
            gvCJ.DataBind();
        }
        else
        {
            if (txtName.Text == "")
            {
                MsgBoxShow("请输入要查询的学生姓名！");
                return;
            }
            gvCJ.DataSource = cj_BLL.GetCJInfo(txtName.Text);
            gvCJ.DataBind();

        }
    }
    //搜索
    protected void ibtnSear_Click(object sender, ImageClickEventArgs e)
    {
        if (txtName.Text == "")
        {
            MsgBoxShow("请输入要查询的学生姓名！");
            return;
        }

        if (dropBJ.SelectedValue == "All")
        {
            gvCJ.DataSource = cj_BLL.GetCJInfo(txtName.Text);
            gvCJ.DataBind();
        }
        else
        {
            gvCJ.DataSource = cj_BLL.GetCJInfo(decimal.Parse(dropBJ.SelectedValue), txtName.Text);
            gvCJ.DataBind();
        }
    }
}
